<html xmlns="http://www.w3.org/1999/xhtml">
<div class="row subsystem-header">
    <div class="pull-left">
        <span style="font-size: 16px;">批次运行历史 <i class="icon-caret-left"></i> 任务组运行历史 <i class="icon-caret-left"></i> 任务运行历史</span>
    </div>
</div>
<div class="row subsystem-toolbar">
    <div style="height: 44px; line-height: 44px;display: inline;">
        <span style="height: 30px; line-height: 30px; margin-top: 7px;display: inline"
              class="pull-left">&nbsp;批次名称 = <span th:text="${batchDesc}"></span></span>
        <span style="height: 30px; line-height: 30px; margin-top: 7px;display: inline"
              class="pull-left">&nbsp;&nbsp;&nbsp;<i style="border: #0b4059 dotted 0.5px; height: 44px;"></i>&nbsp;&nbsp;&nbsp;任务组名称 = <span
                th:text="${groupDesc}"></span></span>
        <span id="h-dispatch-batch-job-history-uuid" style="display: none;" th:text="${uuid}"></span>
        <span id="h-dispatch-batch-job-history-gid" style="display: none;" th:text="${gid}"></span>
    </div>
</div>
<div class="row">
    <div id="h-dispatch-batch-job-monitoring-content" class="col-sm-12 col-md-12 col-lg-12">
        <table id="h-dispatch-batch-job-monitoring-table"
               data-toggle="table"
               data-striped="true"
               data-page-size="30"
               data-toolbar-align="right"
               data-url="/v1/dispatch/batch/job/history"
               data-side-pagination="client"
               data-pagination="true"
               data-page-list="[20,30,50,100]"
               data-search="false">
            <thead>
            <tr>
                <!--<th data-field="state" data-checkbox="true"></th>-->
                <th data-align="center" data-width="46px" data-formatter="BatchJobHistoryObj.formatterindex">序号</th>
                <!--<th data-align="center" data-width="280px" data-field="gid">SuiteKey</th>-->
                <th data-width="320px" data-align="center" data-field="jobKey">JobKey</th>
                <th data-sortable="true" data-field="taskId" data-formatter="BatchJobHistoryObj.formatter">任务编码</th>
                <th data-sortable="true" data-field="taskDesc">任务名称</th>
                <th data-sortable="true" data-field="taskTypeDesc">任务类型</th>
                <th data-sortable="true" data-align="center" data-field="statusDesc">任务状态</th>
                <th data-sortable="true" data-align="center" data-field="startTime">开始日期</th>
                <th data-sortable="true" data-align="center" data-field="endTime">结束时间</th>
                <th data-sortable="true" data-align="center" data-formatter="BatchJobHistoryObj.calcCost">运行时长</th>
                <th data-sortable="true" data-align="center" data-formatter="BatchJobHistoryObj.execLog">运行日志</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/javascript">
    var BatchJobHistoryObj = {
        formatterindex: function (value, row, index) {
            return index + 1;
        },
        formatter: function (value, row, index) {
            return Hutils.getLast(value);
        },
        calcCost: function (value, row, index) {
            /*<![CDATA[*/
            var start = new Date(row.startTime.substr(0, 19));
            var end = new Date(row.endTime.substr(0, 19));

            var diff = (end - start) / 1000;

            if (diff < 0) {
                diff = 0;
            }
            var costTime = diff + "s";

            if (diff >= 60) {
                if (diff % 60 != 0) {
                    costTime = (diff % 60).toFixed(0) + "s";
                }
                // 转换成分钟
                diff = (diff / 60).toFixed(0);
                if (diff >= 60) {
                    if (diff % 60 != 0) {
                        costTime = (diff % 60).toFixed(0) + "m " + costTime;
                    }
                    // 转换成小时
                    diff = (diff / 24).toFixed();
                    if (diff >= 24) {
                        if (diff % 24 != 0) {
                            costTime = (diff % 60).toFixed(0) + "h " + costTime;
                        }
                        costTime = (diff % 24).toFixed(0) + "d" + costTime;
                    } else {
                        costTime = diff + "h " + costTime;
                    }
                } else {
                    costTime = diff + "m " + costTime;
                }
            }
            /*]]>*/
            return costTime;
        },
        execLog: function (value, row, index) {
            return '<span class="h-td-btn btn-success btn-xs" onclick="BatchJobHistoryObj.getLogs(\'' + row.jobId + '\')">查看日志</span>';
        },
        getLogs: function (jobId) {
            var uuid = $("#h-dispatch-batch-job-history-uuid").html();
            $.Hmodal({
                header: "日志信息",
                submitBtn: false,
                height: "500",
                body: $("#h-dispatch-batch-job-monitoring-logs-src").html(),
                preprocess: function () {
                    $("#h-dispatch-batch-job-monitoring-logs-table").bootstrapTable({
                        height: 360,
                        queryParams: function (params) {
                            params.id = uuid;
                            params.job = jobId;
                            return params;
                        }
                    })
                },
            })
        }
    };

    $(document).ready(function () {
        var hwindow = document.documentElement.clientHeight;
        $("#h-dispatch-batch-job-monitoring-content").height(hwindow - 139);

        $("#h-dispatch-batch-job-monitoring-table").bootstrapTable({
            height: hwindow - 139,
            queryParams: function (params) {
                params.uuid = $("#h-dispatch-batch-job-history-uuid").html();
                params.gid = $("#h-dispatch-batch-job-history-gid").html();
                return params;
            },
        })
    });
</script>
<script id="h-dispatch-batch-job-monitoring-logs-src" type="text/html">
    <table id="h-dispatch-batch-job-monitoring-logs-table"
           data-toggle="table"
           data-striped="true"
           data-page-size="30"
           data-unique-id="uuid"
           data-toolbar-align="right"
           data-url="/v1/dispatch/batch/job/history/logs"
           data-side-pagination="client"
           data-pagination="true"
           data-page-list="[20,30,50,100]"
           data-search="false">
        <thead>
        <tr>
            <th data-width="46px" data-align="center" data-valign="middle" data-field="sortId">序号</th>
            <th data-sortable="true" data-width="150px" data-valign="middle" data-align="center" data-field="execTime">
                执行时间
            </th>
            <th data-sortable="true" data-field="message">输出信息</th>
        </tr>
        </thead>
    </table>
</script>
</html>